package main

import (
	"encoding/json"
)

type Result struct {
	Value  string `json:"value,omitempty"`
	code   int
	err    error
	action Action
}

type Action string

const (
	POST = Action("post")
	GET  = Action("get")
)

func NewResult() *Result {
	return &Result{err: nil}
}

func (r *Result) WithAction(act Action) *Result {
	r.action = act
	return r
}

func (r *Result) WithError(err error) *Result {
	r.err = err
	return r
}

func (r *Result) WithValue(value string) *Result {
	r.Value = value
	return r
}

func (r *Result) WithCode(code int) *Result {
	r.code = code
	return r
}

func (r *Result) bytes() []byte {
	b, _ := json.Marshal(r)
	return b
}

func (r *Result) String() (ret string) {
	ret = r.Value
	return
}
